  // Note.swift 修改

import Vapor
import Fluent

final class Note: Model, Content, @unchecked Sendable {
  static var schema: String { SchemaEnum.notes.rawValue }
  
  @ID(key: .id)
  var id: UUID?
  
  @Field(key: FieldKeys.content)
  var content: String
  
  @Field(key: FieldKeys.isPublic)
  var isPublic: Bool
  
    // 音频时间戳（秒）
  @Field(key: FieldKeys.timestamp)
  var timestamp: Double?
  
    // 标签数组
  @Field(key: FieldKeys.tags)
  var tags: [String]?
  
    // 点赞用户ID数组
  @Field(key: FieldKeys.likedBy)
  var likedBy: [UUID]?
  
    // 点赞数量
  @Field(key: FieldKeys.likeCount)
  var likeCount: Int
  
  @Field(key: FieldKeys.reviewStatus)
  var reviewStatus: ReviewStatus
  
    // 新增：答案字段
  @Field(key: FieldKeys.answer)
  var answer: String?
  
    // 新增：内容是否为阿拉伯语
  @Field(key: FieldKeys.isArabic)
  var isArabic: Bool
  
    // 新增：答案是否为阿拉伯语
  @Field(key: FieldKeys.isAnswerArabic)
  var isAnswerArabic: Bool
  
  @Parent(key: FieldKeys.user)
  var user: User
  
  @Parent(key: FieldKeys.audio)
  var audio: Audio
  
  @Timestamp(key: FieldKeys.createdAt, on: .create)
  var createdAt: Date?
  
  @Timestamp(key: FieldKeys.updatedAt, on: .update)
  var updatedAt: Date?
  
  init() { }
  
  init(
id: UUID? = nil,
 content: String,
timestamp: Double?,
tags: [String]?,
userID: User.IDValue,
audioID: Audio.IDValue,
isPublic: Bool = true,
likedBy: [UUID]? = nil,
likeCount: Int = 0,
reviewStatus: ReviewStatus,
answer: String? = nil,
isArabic: Bool = true,
isAnswerArabic: Bool = false,
       createdAt: Date?,
 updatedAt: Date?
) {
    self.id = id
    self.content = content
    self.timestamp = timestamp
    self.tags = tags ?? []
    self.$user.id = userID
    self.$audio.id = audioID
    self.isPublic = isPublic
    self.likedBy = likedBy ?? []
    self.likeCount = likeCount
  self.reviewStatus = reviewStatus
  self.answer = answer
  self.isArabic = isArabic
  self.isAnswerArabic = isAnswerArabic
    self.createdAt = createdAt
    self.updatedAt = updatedAt
  }
  
    // 创建笔记请求
  struct Create: Content {
    let content: String
    let audioID: UUID
    let timestamp: Double?
    let tags: [String]?
    let isPublic: Bool?
    let addToReview: Bool?
    let answer: String? // 新增：答案字段
    let isArabic: Bool? // 新增：内容是否为阿拉伯语
    let isAnswerArabic: Bool? // 新增：答案是否为阿拉伯语
  }
  
    // 更新笔记请求
  struct Update: Content {
    let content: String
    let timestamp: Double?
    let tags: [String]?
    let isPublic: Bool?
    let answer: String? // 新增：答案字段
    let isArabic: Bool? // 新增：内容是否为阿拉伯语
    let isAnswerArabic: Bool? // 新增：答案是否为阿拉伯语
  }
  
    // 笔记响应
  struct Response: Content {
    let id: UUID?
    let content: String
    let timestamp: Double?
    let tags: [String]?
    let userID: UUID
    let audioID: UUID
    let isPublic: Bool
    
      // 点赞相关字段
    let likeCount: Int
    let isLiked: Bool
    
      // 其他字段保持不变
    let audioTitle: String
    let audioCover: String?
    let albumCover: String?
    let userName: String
    let userAvatar: String?
    
    let reviewStatus: ReviewStatus?
    
    let answer: String? // 新增：答案字段
    let isArabic: Bool // 新增：内容是否为阿拉伯语
    let isAnswerArabic: Bool // 新增：答案是否为阿拉伯语
    
    let createdAt: Date?
    let updatedAt: Date?
  }

  struct ReportNoteRequest: Content {
    let noteID: UUID
    let category: Feedback.FeedbackCategory
    let type: Feedback.FeedbackType
    let content: String?
  }
}


  // 添加复习状态枚举
enum ReviewStatus: String, Codable {
  case none        // 未设置复习
  case scheduled   // 已安排复习
  case completed   // 已完成复习
}
